//
//  shouYinTaiViewController.m
//  EJLX
//
//  Created by adc on 15/11/17.
//  Copyright © 2015年 江苏一键联信息科技有限公司. All rights reserved.
//

#import "shouYinTaiViewController.h"
#import "ShouYinTaiTableViewCell.h"
#import "YiBaoZhiFuViewController.h"
#import "JingDongZhiFuViewController.h"
#import "HttpsManager.h"

@interface shouYinTaiViewController ()<UIViewControllerCallBackProtocol>


@end

@implementation shouYinTaiViewController
-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden=YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBar.barTintColor = RGB_COLOR(0x00c49f);
    
    [[CsPaySDK shardUserInfo]initWithToken:@"18036097561" secret:@"123456" option:nil withCallBack:self];
    UILabel*nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(5, 70,60, 20)];
    nameLabel.text=@"订单名称:";
    nameLabel.textColor=[UIColor blackColor];
    nameLabel.font=[UIFont systemFontOfSize:12];
    [self.view addSubview:nameLabel];
    UILabel*nameLabel1=[[UILabel alloc]initWithFrame:CGRectMake(70,70,120, 20)];
    nameLabel1.textColor=[UIColor blackColor];
    nameLabel1.text=@"一键联o2o收银订单";
     nameLabel1.font=[UIFont systemFontOfSize:12];
    [self.view addSubview:nameLabel1];
    UILabel*monyLabel=[[UILabel alloc]initWithFrame:CGRectMake(5,120,50, 20)];
    monyLabel.text=@"总金额:";
    monyLabel.textColor=[UIColor blackColor];
    monyLabel.font=[UIFont systemFontOfSize:12];
    [self.view addSubview:monyLabel];
  monyLabel1=[[UILabel alloc]initWithFrame:CGRectMake(50,120,50, 20)];
    monyLabel1.text=_mony;
    monyLabel1.textColor=[UIColor  blackColor];
    monyLabel1.font=[UIFont systemFontOfSize:12];
    [self.view addSubview:monyLabel1];
    
    
    self.view.backgroundColor=[UIColor whiteColor];
      UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0,20,WIDE, 44)];
    view.backgroundColor=RGB_COLOR(0x00c49f);
    [self.view addSubview:view];
    UIButton*backBut=[[UIButton alloc]initWithFrame:CGRectMake(10,7,30,30)];
    [backBut setImage:[UIImage imageNamed:@"返回箭头"] forState:UIControlStateNormal];
    [backBut addTarget:self action:@selector(butClick) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:backBut];
    UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(WIDE/2-50, 10,100, 24)];
    label.text=@"020收银台";
    label.textColor=[UIColor whiteColor];
    [view addSubview:label];
    UITableView*tableView=[[UITableView alloc]initWithFrame:CGRectMake(0,150,WIDE,HEIGHT-120-30) style:UITableViewStylePlain];
    tableView.delegate=self;
    tableView.dataSource=self;
    tableView.rowHeight=44;
    tableView.separatorStyle=NO;
    [self.view addSubview:tableView];
    [tableView registerNib:[UINib nibWithNibName:@"ShouYinTaiTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
    
   }
//-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//{
//    return 3;
//}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //    if (section==0)
    //    {
    //        return 2;
    //    }
    //    if (section==1)
    //    {
    //        return 2;
    //    }
    return 5;
}
//-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
//{
//    return 20;
//}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray*ary=[NSArray arrayWithObjects:@"易宝支付",@"京东支付",@"支付宝支付",@"微信支付",@"蓝牙刷卡器", nil];
    ShouYinTaiTableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    //    if (indexPath.section==0)
    //    {
    //        NSArray*ary=[NSArray arrayWithObjects:@"易宝支付T+1",@"易宝支付T+0", nil];
    //        cell.label.text=ary[indexPath.row];
    //        return cell;
    //    }
    //    if (indexPath.section==1)
    //    {
    //        NSArray*ary=[NSArray arrayWithObjects:@"京东支付",@"京东支付0费率", nil];
    //        cell.label.text=ary[indexPath.row];
    //        return cell;
    //    }
    cell.label.text=ary[indexPath.row];
     cell.picture.image=[UIImage imageNamed:ary[indexPath.row]];
    
    
    return cell;
}
//返回按钮
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row)
    {
        case 0:
        {
            int a=[monyLabel1.text intValue];
            NSString*totalCharge=[NSString stringWithFormat:@"%d",a*100];
            o2oShouYinTai*o2o=[[o2oShouYinTai alloc]init];
            o2o.totalCharge=totalCharge;
            o2o.paymentType=@"3";
            o2o.o2o=_o2o;
            //NSMutableString*ss=[[NSMutableString alloc]init];
            o2o.orderIdStr=_orderId;
            
            [HttpsManager requestGet020ShouYinTai:o2o Competion:^(ZhiFuDiaoYongJIeKou *zhiFu)
            {
                if (zhiFu!=nil)
                {
                    _zhiFu=zhiFu;
                    YiBaoZhiFuViewController*vc=[[YiBaoZhiFuViewController alloc]init];
                    vc.yiBaoMoney=[NSString stringWithFormat:@"%d",_zhiFu.amount];
                    
                    vc.paymentId=[NSString stringWithFormat:@"%d",_zhiFu.paymentId];
                    
                    NSLog(@"%d",zhiFu.amount);
                    [self.navigationController pushViewController:vc animated:YES];
                }
                else
                {
                    LoginVC*vc=[[LoginVC alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                    
                }
                
            }];
            
        }
            break;
        case 1:
        {
            int a=[monyLabel1.text intValue];
            NSString*totalCharge=[NSString stringWithFormat:@"%d",a*100];
            o2oShouYinTai*o2o=[[o2oShouYinTai alloc]init];
            o2o.totalCharge=totalCharge;
            o2o.paymentType=@"4";
            o2o.o2o=_o2o;
            NSLog(@"qqq%@",_orderId);
            o2o.orderIdStr=_orderId;
            [HttpsManager requestGet020ShouYinTai:o2o Competion:^(ZhiFuDiaoYongJIeKou *zhiFu)
             {
                 if (zhiFu!=nil)
                 {
                     _zhiFu=zhiFu;
                     JingDongZhiFuViewController*vc=[[JingDongZhiFuViewController alloc]init];
                     
                     
                     vc.paymentId=[NSString stringWithFormat:@"%d",_zhiFu.paymentId];
                     
                     
                     [self.navigationController pushViewController:vc animated:YES];
                 }
                 
                 else
                 {
                     LoginVC*vc=[[LoginVC alloc]init];
                     [self.navigationController pushViewController:vc animated:YES];
                     
                 }
             }];

            
        }
            break;
        case 2:
        {
            
            Paymodel * paymodel = [Paymodel new];
            paymodel.amount = _mony;
            self.navigationController.navigationBarHidden =NO;
            //paymodel.navigationController.hidesBottomBarWhenPushed=YES;
            paymodel.pay_type = @"支付宝支付";
            paymodel.orderno = [self random];
            [[CsPaySDK shardUserInfo]payWithPaymodel:paymodel controller:self withCallBack:self];
        }
            break;
        case 3:
        {
           
            Paymodel * paymodel = [Paymodel new];
            // paymodel.navigationController.hidesBottomBarWhenPushed=YES;
            paymodel.amount = _mony;
            self.navigationController.navigationBarHidden =NO;
            paymodel.pay_type = @"微信支付";
            paymodel.orderno = [self random];
            [[CsPaySDK shardUserInfo]payWithPaymodel:paymodel controller:self withCallBack:self];
        }
            break;
        case 4:
        {
           
            Paymodel * paymodel = [Paymodel new];
            paymodel.amount =_mony;
            // paymodel.navigationController.hidesBottomBarWhenPushed=YES;
            self.navigationController.navigationBarHidden =NO;
            paymodel.orderno = @"123";
            paymodel.pay_type = @"蓝牙刷卡";
            [[CsPaySDK shardUserInfo]payWithPaymodel:paymodel controller:self withCallBack:self];
        }
            break;
        case 5:
        {
            
        }
            break;
        case 6:
        {
            
        }
            break;
        default:
            break;
    }
}
-(void)callBackWith:(NSString *)mark success:(BOOL)success parameter:(id)paramater{
    if(success){
        NSLog(@"%@",paramater);
//        self.wechatBtn.enabled = YES;
//        self.alipayBtn.enabled = YES;
//        self.deviceBtn.enabled = YES;
        
    }else{
        NSLog(@"%@",paramater);
        if ([paramater isEqualToString:@"-2"]) {
            UIAlertView * aler = [[UIAlertView alloc]initWithTitle:@"提示:" message:@"网络连接失败" delegate:nil cancelButtonTitle:@"好" otherButtonTitles:nil, nil];
            [aler show];
//            self.wechatBtn.enabled = NO;
//            self.alipayBtn.enabled = NO;
//            self.deviceBtn.enabled = NO;
        } else if ([paramater isEqualToString:@"-4"]) {
            UIAlertView * aler = [[UIAlertView alloc]initWithTitle:@"提示:" message:@"请设置金额" delegate:nil cancelButtonTitle:@"好" otherButtonTitles:nil, nil];
            [aler show];
        } else if ([paramater isEqualToString:@"-5"]) {
            UIAlertView * aler = [[UIAlertView alloc]initWithTitle:@"提示:" message:@"登录失败" delegate:nil cancelButtonTitle:@"好" otherButtonTitles:nil, nil];
            [aler show];
        }
    }
}
-(void)callBackResultWith:(BOOL)success parameter:(id)paramater mark:(NSString *)mark{
    if (success) {
        if ([mark isEqualToString:@"蓝牙刷卡"]) {
            NSLog(@"蓝牙刷卡     +++消费成功+++");
        } else if ([mark isEqualToString:@"微信支付"]) {
            NSLog(@"微信支付     +++消费成功+++");
            
        } else if ([mark isEqualToString:@"支付宝支付"]) {
            NSLog(@"支付宝支付     +++消费成功+++");
        }
    } else {
        if ([mark isEqualToString:@"蓝牙刷卡"]) {
            NSLog(@"蓝牙刷卡     %@", paramater);
        } else if ([mark isEqualToString:@"微信支付"]) {
            NSLog(@"微信支付     %@", paramater);
        } else if ([mark isEqualToString:@"支付宝支付"]) {
            NSLog(@"支付宝支付    %@", paramater);
        }
    }
}
-(NSString *)random{
    NSString * string;
    int value = arc4random() % 1000000000;
    string = [NSString stringWithFormat:@"%d",value];
    return string;
}

-(void)butClick
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
}
@end


